<?php

namespace app;

/**
 * socket异常
 */
class CustomException extends \Exception
{

    /**
     * data数据
     * @var array|mixed
     */
    protected $data = [];

    public function __construct($msg = '', $code = 500, $data = [])
    {
        parent::__construct();
        $this->message = $msg;
        $this->code = $code;
        $this->data = $data;
    }

    /**
     * 获取data数据
     * @return array|mixed
     */
    public function getData()
    {
        return $this->data;
    }

    /**
     * 获取返回值
     * @return array
     */
    public function getRender()
    {
        return [
            'code' => $this->code,
            'msg' => $this->message,
            'data' => $this->data
        ];
    }

}